package com.app.biz.controller;

import cn.hutool.core.util.IdUtil;
import com.app.biz.domain.BizServiceConsultation;
import com.app.biz.service.IBizServiceConsultationService;
import com.app.common.annotation.Log;
import com.app.common.core.controller.BaseController;
import com.app.common.core.domain.AjaxResult;
import com.app.common.core.page.TableDataInfo;
import com.app.common.enums.BusinessType;
import com.app.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 服务咨询Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/biz/consultation")
public class BizServiceConsultationController extends BaseController
{
    @Autowired
    private IBizServiceConsultationService bizServiceConsultationService;


    /**
     * 查询服务咨询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BizServiceConsultation bizServiceConsultation)
    {
        startPage();
        List<BizServiceConsultation> list = bizServiceConsultationService.selectBizServiceConsultationList(bizServiceConsultation);
        return getDataTable(list);
    }

    /**
     * 导出服务咨询列表
     */
    @Log(title = "服务咨询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizServiceConsultation bizServiceConsultation)
    {
        List<BizServiceConsultation> list = bizServiceConsultationService.selectBizServiceConsultationList(bizServiceConsultation);
        ExcelUtil<BizServiceConsultation> util = new ExcelUtil<BizServiceConsultation>(BizServiceConsultation.class);
        util.exportExcel(response, list, "服务咨询数据");
    }

    /**
     * 获取服务咨询详细信息
     */
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(bizServiceConsultationService.selectBizServiceConsultationByBaseId(baseId));
    }

    /**
     * 新增服务咨询
     */
    @Log(title = "服务咨询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizServiceConsultation bizServiceConsultation)
    {
        bizServiceConsultation.setBaseId(IdUtil.simpleUUID());
        bizServiceConsultation.setBaseCreateTime(new Date());
        return toAjax(bizServiceConsultationService.insertBizServiceConsultation(bizServiceConsultation));
    }

    /**
     * 修改服务咨询
     */
    @Log(title = "服务咨询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizServiceConsultation bizServiceConsultation)
    {
        return toAjax(bizServiceConsultationService.updateBizServiceConsultation(bizServiceConsultation));
    }

    /**
     * 删除服务咨询
     */
    @Log(title = "服务咨询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(bizServiceConsultationService.deleteBizServiceConsultationByBaseIds(baseIds));
    }
}
